home *** CD-ROM | disk | FTP | other *** search
/ Network CD 1 / Network CD.iso / fredfish / 881-890 / ff890 / sltchr / sltchr.c < prev   
Text File  |  1993-07-16  |  7KB  |  269 lines

  1. /* Select a character from ASDG CygnusEd */
  2. /* assign to function key for easy access */
  3.  
  4. /* Njål Fisketjøn 930604 */
  5.  
  6.  
  7. #include <exec/types.h>
  8. #include <exec/ports.h>
  9. #include <exec/nodes.h>
  10. #include <intuition/sghooks.h>
  11. #include <intuition/intuition.h>
  12. #include <intuition/gadgetclass.h>
  13. #include <libraries/gadtools.h>
  14.  
  15. #include <clib/alib_protos.h>
  16. #include <clib/exec_protos.h>
  17. #include <clib/graphics_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/gadtools_protos.h>
  20.  
  21. #include <stdio.h>
  22. #include <string.h>
  23.  
  24. #include "ced.h"
  25.  
  26. #ifdef LATTICE
  27. int CXBRK(void)        { return(0); }
  28. int chkabort(void)    { return(0); }
  29. #endif
  30.  
  31. #define RXFB_RESULT 17
  32.  
  33. struct CedMsg TheMessage;
  34. struct MsgPort *CedPort;
  35. struct MsgPort *MyPort;
  36. char TheCommand[80];
  37.  
  38. struct TextAttr Topaz80 = {"topaz.font", 8, 0, 0, } ;
  39.  
  40. struct IntuiText Copyright = {2, 0, JAM1, 300, 160, NULL, 
  41.     "Copyright © 1993 N Fisketjøn", NULL};
  42.  
  43. struct IntuiText IText7 = {1, 0, JAM1, 14, 143,    NULL,
  44.     "à á â ã ä å æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ÷ ø ù ú û ü ý þ ÿ",
  45.     &Copyright};
  46.  
  47. struct IntuiText IText6 = {1, 0, JAM1, 14, 127,    NULL,
  48.     "À Á Â Ã Ä Å Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö × Ø Ù Ú Û Ü Ý Þ ß", &IText7};
  49.  
  50. unsigned char string5b[]={0xa8,0x00};
  51. struct IntuiText IText5b = {1, 0, JAM1, 142, 111, NULL, string5b, &IText6};
  52.  
  53. struct IntuiText IText5 = {1, 0, JAM1, 14, 111,    NULL,
  54.     "  ¡ ¢ £ ¤ ¥ ¦ §   © ª « ¬ ­ ® ¯ ° ± ² ³ ´ µ ¶ · ¸ ¹ º » ¼ ½ ¾ ¿", &IText5b};
  55.  
  56. unsigned char string4[]={0x80,0x20,0x81,0x20,0x82,0x20,0x83,0x20,0x84,0x20,0x85,0x20,0x86,0x20,0x87,0x20,
  57.                 0x88,0x20,0x89,0x20,0x8a,0x20,0x8b,0x20,0x8c,0x20,0x8d,0x20,0x8e,0x20,0x8f,0x20,
  58.                 0x90,0x20,0x91,0x20,0x92,0x20,0x93,0x20,0x94,0x20,0x95,0x20,0x96,0x20,0x97,0x20,
  59.                 0x98,0x20,0x99,0x20,0x9a,0x20,0x9b,0x20,0x9c,0x20,0x9d,0x20,0x9e,0x20,0x9f,0x20,0x00};
  60. struct IntuiText IText4 = {1, 0, JAM1, 14, 95,    NULL, string4, &IText5};
  61.  
  62. struct IntuiText IText3 = {1, 0, JAM1, 14, 79,    NULL,
  63.     "` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ ", &IText4};
  64.  
  65. unsigned char string2b[]={0x5c,0x00};
  66. struct IntuiText IText2b = {1, 0, JAM1, 462, 63, NULL, string2b, &IText3};
  67.  
  68. struct IntuiText IText2 = {1, 0, JAM1, 14, 63,    NULL,
  69.     "@ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [   ] ^ _", &IText2b};
  70.  
  71. unsigned char string1b[]={0x22,0x00};
  72. struct IntuiText IText1b = {1, 0, JAM1, 46, 47,    NULL, string1b, &IText2};
  73.  
  74. struct IntuiText IText1 = {1, 0, JAM1, 14, 47,    NULL,
  75.     "  !   # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ?", &IText1b};
  76.  
  77. unsigned char string0[]={0x20,0x20,0x01,0x20,0x02,0x20,0x03,0x20,0x04,0x20,0x05,0x20,0x06,0x20,0x07,0x20,
  78.                 0x08,0x20,0x09,0x20,0x0a,0x20,0x0b,0x20,0x0c,0x20,0x0d,0x20,0x0e,0x20,0x0f,0x20,
  79.                 0x10,0x20,0x11,0x20,0x12,0x20,0x13,0x20,0x14,0x20,0x15,0x20,0x16,0x20,0x17,0x20,
  80.                 0x18,0x20,0x19,0x20,0x1a,0x20,0x1b,0x20,0x1c,0x20,0x1d,0x20,0x1e,0x20,0x1f,0x20,0x00};
  81. struct IntuiText IText0 = {1, 0, JAM1, 14, 31,    NULL, string0, &IText1};
  82.  
  83. struct Library *IntuitionBase;
  84. struct Library *GfxBase;
  85. struct Library *GadToolsBase;
  86.  
  87. void errorMessage(STRPTR error)
  88. {
  89. if (error)
  90.     printf("Error: %s\n",error);
  91. }
  92.  
  93. struct Gadget *createAllGadgets(struct Gadget **glistptr, void *vi,
  94.     UWORD topborder)
  95. {
  96. int i,j;
  97.  
  98. struct NewGadget ng;
  99. struct Gadget *gad;
  100.  
  101. gad= CreateContext(glistptr);
  102.  
  103. ng.ng_Height     = 16;
  104. ng.ng_Width         = 16;
  105. ng.ng_GadgetText = "";
  106. ng.ng_TextAttr     = &Topaz80;
  107. ng.ng_VisualInfo = vi;
  108. ng.ng_Flags         = NG_HIGHLABEL;
  109.  
  110. for(i=0; i<=31; i++)
  111. {
  112.     for(j=0; j<=7; j++)
  113.     {
  114.     ng.ng_TopEdge    = 10 + (j*ng.ng_Height) + topborder;
  115.     ng.ng_LeftEdge    = 10 + (i*ng.ng_Width);
  116.     ng.ng_GadgetID    = j*32 + i;
  117.     gad = CreateGadget(BUTTON_KIND, gad, &ng, TAG_END);
  118.     }
  119. }
  120.  
  121. return(gad);
  122. }
  123.  
  124. VOID SendCygnusEdMessageGetReply(char *TheCommand)
  125.  
  126. {
  127.     TheMessage.cm_Args[0] = TheCommand;
  128.     TheMessage.cm_Node.mn_Node.ln_Type = NT_MESSAGE;
  129.     TheMessage.cm_Node.mn_Length = sizeof(struct CedMsg);
  130.     TheMessage.rm_Action= 1l << RXFB_RESULT;
  131.     TheMessage.rm_Result2 = 0;
  132.  
  133.     if (!(CedPort = FindPort("rexx_ced")))
  134.         errorMessage(" Unable to find Ced rexx port");
  135.     if (!(MyPort = CreatePort("SltChr", 0L)))
  136.         errorMessage(" Unable to create message port");
  137.  
  138.     TheMessage.cm_Node.mn_ReplyPort    = MyPort;
  139.     PutMsg(CedPort, &TheMessage);
  140.     WaitPort(MyPort);
  141.     DeletePort(MyPort);
  142. }
  143.  
  144. VOID process_window_events(struct Window *mywin)
  145. {
  146. struct IntuiMessage *imsg;
  147. ULONG imsgClass;
  148. UWORD imsgCode;
  149. struct Gadget *gad;
  150. BOOL terminated = FALSE;
  151.  
  152. while (!terminated)
  153.     {
  154.     Wait (1 << mywin->UserPort->mp_SigBit);
  155.  
  156.     while ((!terminated) &&
  157.            (imsg = GT_GetIMsg(mywin->UserPort)))
  158.         {
  159.         gad = (struct Gadget *)imsg->IAddress;
  160.  
  161.         imsgClass = imsg->Class;
  162.         imsgCode = imsg->Code;
  163.  
  164.         GT_ReplyIMsg(imsg);
  165.  
  166.         switch (imsgClass)
  167.             {
  168.             case IDCMP_GADGETDOWN:
  169.             case IDCMP_MOUSEMOVE:
  170.             case IDCMP_GADGETUP:
  171.                 PrintIText(mywin->RPort,&IText0,0,0);
  172.                 sprintf(TheCommand,"enter ascii %i",gad->GadgetID);
  173.                 SendCygnusEdMessageGetReply(TheCommand);
  174.                 break;
  175.             case IDCMP_CLOSEWINDOW:
  176.                 terminated = TRUE;
  177.                 break;
  178.             case IDCMP_REFRESHWINDOW:
  179.                 GT_BeginRefresh(mywin);
  180.                 GT_EndRefresh(mywin, TRUE);
  181.                 break;
  182.             }
  183.         }
  184.     }
  185. }
  186.  
  187. VOID gadtoolsWindow(void)
  188. {
  189. struct TextFont *font;
  190. struct Screen    *mysc;
  191. struct Window    *mywin;
  192. struct Gadget    *glist;
  193. void            *vi;
  194. UWORD            topborder;
  195.  
  196. if (NULL == (font = OpenFont(&Topaz80)))
  197.     errorMessage( "Failed to open Topaz 80");
  198. else
  199.     {
  200.     if (NULL == (mysc = LockPubScreen(NULL)))
  201.         errorMessage( "Couldn't lock default public screen");
  202.     else
  203.         {
  204.         if (NULL == (vi = GetVisualInfo(mysc, TAG_END)))
  205.             errorMessage( "GetVisualInfo() failed");
  206.         else
  207.             {
  208.             topborder = mysc->WBorTop + (mysc->Font->ta_YSize + 1);
  209.  
  210.             if (NULL == createAllGadgets(&glist, vi, topborder))
  211.                 errorMessage( "createAllGadgets() failed");
  212.             else
  213.                 {
  214.                 ScreenToFront(mysc);
  215.                 if (NULL == (mywin = OpenWindowTags(NULL,
  216.                         WA_Title,      "Select character(s) and close window",
  217.                         WA_Gadgets,      glist,      WA_AutoAdjust,    TRUE,
  218.                         WA_Width,        532,      WA_MinWidth,           0,
  219.                         WA_InnerHeight, 165,      WA_MinHeight,           0,
  220.                         WA_DragBar,       TRUE,      WA_DepthGadget,  FALSE,
  221.                         WA_Activate,   TRUE,      WA_CloseGadget,    TRUE,
  222.                         WA_SizeGadget, FALSE,      WA_SimpleRefresh, TRUE,
  223.                         WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_REFRESHWINDOW |
  224.                             BUTTONIDCMP ,
  225.                         WA_PubScreen, mysc,
  226.                         TAG_END)))
  227.                     errorMessage( "OpenWindow() failed");
  228.                 else
  229.                     {
  230.                     PrintIText(mywin->RPort,&IText0,0,0);
  231.                     GT_RefreshWindow(mywin, NULL);
  232.                     process_window_events(mywin);
  233.                     CloseWindow(mywin);
  234.                     }
  235.                 }
  236.             FreeGadgets(glist);
  237.             FreeVisualInfo(vi);
  238.             }
  239.         UnlockPubScreen(NULL, mysc);
  240.         }
  241.     CloseFont(font);
  242.     }
  243. }
  244.  
  245. VOID main(void)
  246. {
  247.  
  248. if (NULL == (IntuitionBase = OpenLibrary("intuition.library", 37)))
  249.     errorMessage( "Requires V37 intuition.library");
  250. else
  251.     {
  252.     if (NULL == (GfxBase = OpenLibrary("graphics.library", 37)))
  253.         errorMessage(" Requires V37 graphics.library");
  254.     else
  255.         {
  256.         if (NULL == (GadToolsBase = OpenLibrary("gadtools.library", 37)))
  257.             errorMessage(" Requires V37 gadtools.library");
  258.         else
  259.             {
  260.             gadtoolsWindow();
  261.             CloseLibrary(GadToolsBase);
  262.             }
  263.         CloseLibrary(GfxBase);
  264.         }
  265.     CloseLibrary(IntuitionBase);
  266.     }
  267. SendCygnusEdMessageGetReply("Cedtofront");
  268. }
  269.